﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Cdp
{
    public class CdpGenerater
    {
        object obj = new object();
        short ps = -1;
        short ms = -1;

        public short GetPSequence()
        {
            lock (obj)
            {
                ps++;
                return ps;
            }
        }


        public short GetMSequence()
        {
            lock (obj)
            {
                ms++;
                return ms;
            }
        }

        public static int GetTimestamp()
        {
            TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            return Convert.ToInt32(ts.TotalSeconds);
        }

        public static int GetMicroTimestamp()
        {
            return Convert.ToInt32(DateTime.UtcNow.Millisecond * 1000);
        }
    }
}
